Berkeley CS 61C Lecture 5

Here are some notes and corrections on this lecture:

Each note begins with a time; "ca." in front of a time means that it is approximate.

ca. 24:00 -- a student asks why we should bother with $t0 instead of just using $s0 as the temporary register. His answer doesn't really apply to the particular situation he has. The $s0 register is going to be changed anyway. My answer is, "Yeah, that would work fine here, but there will be cases where it wouldn't be good (for the reasons he gives), and besides, we're wanting to introduce the concept of temporary registers and how they are generally used."

  add  $s0  $s1  $s2
  add  $s0  $s0  $s3
  sub  $s0  $s0  $s4

ca. 27:00 -- he is explaining why we have immediate mode. We could work around not having it this way:

.data
one:   .word 1
.text
lw   $t0  one
add  $s0  $s1  $t0

will do the same thing as "addi $s0 $s1 1". He gives some good reasons why we don't like that.

ca 30:00 -- In his example of overflow, he is working in a 4-bit world. We don't do that; we work in a 32-bit world. Imagine how hard his example would be to look at and understand if he had made it work in a 32-bit world; and it wouldn't have fit the slide very well, either. The same principle applies whatever the size of your world: when the operation produces more bits than will fit in your world, the excess bits are simply lost from the left end of the result, and the answer won't be the correct one because the correct answer won't fit in the space allowed.

ca. 34:00 -- The slide shows a device labeled "PC" or "Program Counter"; this is an internal register in the CPU (i.e. not one of our 32 general-purpose registers) that always holds the address of the next instruction to be executed. We will give it much attention soon and for the rest of the semester.

ca. 41:00 -- He does an example using an array. I want to do this in more detail in class using MARS. The book has a similar example on pp 69-71. Be sure you know that their first go at it on page 69 is deliberately wrong. They correct it on page 70. That's not the only time the book will do that to you.

51:33 -- He says "bytes" when he means "bits". He talks about sign-extending at about the same time. That's another thing that we will get to soon. Everything we have done so far is unsigned. One thing at a time.

1.07:32 -- He says "right" when he means "left". In this context, I have a personal rule: don't use shift operations arithmetically. It's true that you can multiply and divide by powers of 2 that way, but I'd rather just use the multiply and divide operators that the CPU gives us, and I'd rather that you did, too. That is, when I do a shift, I'm doing it to a collection of bits that I'm not thinking of as a numeric value.

ca. 1.11:00 -- Several times he says "equivalent" when he means "equal". Eventually he stops doing that.